<script setup lang="ts">
import { ref } from 'vue'
import { useCenterStore } from '@/stores'

// 表单实例
const formRef = ref()
const useCenter = useCenterStore()
// 添加中心表单
const formData = ref({
  centerName: '',
  address: '',
  responsiblePerson: '',
  contact: '',
  serviceType: []
})

// 添加中心-form校验
const rules: object = {
  centerName: [{ required: true, message: '请输入中心名称', trigger: 'blur' }],
  address: [
    { required: true, message: '请输入地址', trigger: 'blur' },
    { min: 6, message: '用户名必须是6位以上的字符', trigger: 'blur' }
  ],
  responsiblePerson: [
    { required: true, message: '请输入负责人姓名', trigger: 'blur' }
  ],
  contact: [
    { required: true, message: '请输入联系方式', trigger: 'blur' },
    {
      pattern: /^1[3-9]\d{9}$/,
      message: '请输入正确的手机号格式',
      trigger: 'blur'
    }
  ],
  serviceType: [{ required: true, message: '请勾选服务套餐', trigger: 'blur' }]
}

defineExpose({
  formRef
})

const submitForm = async () => {
  // await FireCenterDetailsForm2.value.formRef.validate()
  console.log('过校验了没')
  useCenter.centerChange(false)
}
</script>

<template>
  <div class="fireCenterDetailsForm-page">
    <el-form
      :model="formData"
      label-width="120px"
      ref="formRef"
      :rules="rules"
      size="medium"
    >
      <el-form-item label="中心名称" prop="centerName">
        <el-input
          v-model="formData.centerName"
          placeholder="请输入中心名称"
        ></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="formData.address"
          placeholder="请输入地址"
        ></el-input>
      </el-form-item>
      <el-form-item label="负责人" prop="responsiblePerson">
        <el-input
          v-model="formData.responsiblePerson"
          placeholder="请输入负责人姓名"
        ></el-input>
      </el-form-item>
      <el-form-item label="联系方式" prop="contact">
        <el-input
          v-model="formData.contact"
          placeholder="请输入联系方式"
        ></el-input>
      </el-form-item>
      <el-form-item label="服务套餐" prop="serviceType">
        <el-checkbox-group v-model="formData.serviceType">
          <el-checkbox :key="0" :value="0" label="现场">现场端</el-checkbox>
          <el-checkbox :key="1" :value="1" label="中心端">中心端</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
    <el-footer>
      <el-button type="primary" @click="submitForm"> 保存 </el-button>
    </el-footer>
  </div>
</template>

<style lang="scss" scoped>
.el-form {
  padding: 30px 55px 0 0;
  margin: 1% 5%;
  //   border-top: 1px solid #ccc;
}
.el-footer {
  text-align: center;
}
</style>
